#pragma once
#include "..\String\NWString.h"

class NFile
{
public:
	static NWString ReadFile(NWString FileName)
	{
		FILE *fp = _wfopen(FileName.GetBuffer(),L"rt,ccs=UNICODE");
		int Size = 0;
		while(fgetwc(fp) != WEOF)
			Size++;
		rewind(fp);
		LPTSTR lpBuffer = new WCHAR[Size + 1];
		int i = 0;
		while(!feof(fp))
		{
			lpBuffer[i] = fgetwc(fp);
			i++;
		}
		lpBuffer[Size] = 0;
		fclose(fp);
		NWString Result = lpBuffer;
		delete[] lpBuffer;
		return Result;
	}

	static void WriteFile(NWString FileName,NWString Code)
	{
		FILE *fp = _wfopen(FileName.GetBuffer(),L"wt,ccs=UNICODE");
		int i = 0;
		while(Code[i])
			fputwc(Code[i++],fp);
		fclose(fp);
	}

	static void WriteFileTail(NWString FileName,NWString Code)
	{
		FILE *fp = _wfopen(FileName.GetBuffer(),L"at,ccs=UNICODE");
		int i = 0;
		while(Code[i])
			fputwc(Code[i++],fp);
		fclose(fp);
	}
};